﻿@{
    ViewBag.Title = "受理事件任务列表母页";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}

@section Scripts{
    <script type="text/javascript">

        var EventCode = $("#txtECID").val();
        // var EventCode = "201004011319350019";
        var AcceptOrder = $("#txtAOID").val();
        // var AcceptOrder = 2;
        $(document).ready(function () {

            $.setDivOnly("#divIndex");
            changetabs();
        });
        $(window).resize(function () {
            $.setDivOnly("#divIndex");
        });


        //加一个新的 Tab
        function newTab(i) {
            var $tbs = $('#tbs');//获取tab容器
            var timetitle = '第' + i + '次受理';

            //判断出车次数时候大于0，如果大于，将字体变红色
            //var taskTimes = $('#IDtaskTimes').val();
            //if (taskTimes > 0) {
            //    timetitle.style.color = 'red';
            //}
            var options = {
                title: timetitle,
                iconCls: 'icon-custom-cUser',
                //content: newIframe(url, i),
                closable: false
            };
           {
                $tbs.tabs('add', options);
                //var aa=  $tbs.tabs('select', 0);
            }
        }
        //返回一个<iframe></iframe>标签  撑满子页面
        function newIframe(url, i) {
            var ifid = "'Numid" + i + "'";  //给iframe一个ID ，这个就是唯一，不会出现不知道将iframe下 嵌于哪一个tabs的下面的情况了 。
            var ifrStr = "<iframe id=" + ifid + "  src='" + url + "' style='width:99.5%;height:99%;border:0px solid #000;scrolling:no; '></iframe>";
            return ifrStr;
        }
        function changetabs() {
            //判断如果受理序号>=1，做循环执行newTabs,一次受理一个tabs，展开无法关闭
            if (AcceptOrder >= 1) {
                for (var i = 0; i < AcceptOrder; i++) {
                    (function (j) { newTab(i + 1); })(i);//闭包


                }
            }
              $('#tbs').tabs({
                  onSelect: function (title, index) {  //当更改选项时，获取选择面板更新子内容加载
                      var selecttab = $('#tbs').tabs('getSelected');  // 获取选择的面板
                      var selectindex = $('#tbs').tabs('getTabIndex', selecttab);
                      var i = selectindex;
                      var tabindex = i + 1;
                      var url = '@Url.Content("~/DD/AcceptEvent/AcceptEventTaskInfo?EventCode=" )' + encodeURIComponent(EventCode) + "&AcceptOrder=" + tabindex;
                      $('#tbs').tabs('update', {
                          tab: selecttab,
                          options: {
                              content: newIframe(url, i)  // 新内容的URL
                          }
                      });
                  }
              });


            // var aa = $('#tbs').tabs('select', 0);
            // if (AcceptOrder == 1 || aa) { //当只有一次受理或者默认选择第一次受理时，第一次受理的子内 容加载进来
            if (AcceptOrder == 1) {
                var firsttab = $('#tbs').tabs('getTab', 0);
                var url = '@Url.Content("~/DD/AcceptEvent/AcceptEventTaskInfo?EventCode=" )' + encodeURIComponent(EventCode) + "&AcceptOrder=" + 1;
                $('#tbs').tabs('update', {
                    tab: firsttab,
                    options: {
                        content: newIframe(url, 0)  // 新内容的URL
                    }
                });
            }
            else if (AcceptOrder > 1) {
                var OrderList = $('#IDOrderList').val();             
                $('#tbs').tabs('select', OrderList - 1);
                var setab = $('#tbs').tabs('getTab', OrderList-1);
                var url = '@Url.Content("~/DD/AcceptEvent/AcceptEventTaskInfo?EventCode=" )' + encodeURIComponent(EventCode) + "&AcceptOrder=" + OrderList;
                $('#tbs').tabs('update', {
                    tab: setab,
                    options: {
                        content: newIframe(url, OrderList)  // 新内容的URL
                    }
                });

            }

        }
    </script>
}
<div id="divIndex" class="easyui-layout" style="width:auto; height: auto; margin-left: auto;margin-right: auto">
    <input name="EventCode" type="hidden" id="ECID" value="@ViewBag.EventCode" />
    <input name="txtEC" type="hidden" id="txtECID" value="@ViewBag.txtEC" />
    <input name="txtAO" type="hidden" id="txtAOID" value="@ViewBag.txtAO" />
    <input name="OrderList" type="hidden" id="IDOrderList" value="@ViewBag.OrderList" />

    <div id="divIndexMain" data-options="region:'center'" style="padding: 5px; background:#E4F2FB;">
        <div id="tbs" class="easyui-tabs" data-options="fit:true,border:false,tabPosition:'left',headerWidth:'100'">
        </div>
    </div>
</div>
